﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace JqueryNet.WinFormControl
{
    public class WControl : IJQueryForm
    {

        private Control _control;

        public WControl(Control _control)
        {
            FControl = _control;
            this._control = _control;
        }

        #region IJQueryForm 成员

        public object Value { get; set; }

        public System.Windows.Forms.Control FControl { get; set; }

        public virtual void Val()
        {
            Value = _control.Text;
        }

        public virtual void Val(string value)
        {
            _control.Text = value;
        }

        public virtual void Val(Func<string> fun)
        {
            Val(fun());
        }

        public virtual void Val(string[] values)
        {
            if (values != null && values.Length > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (string item in values)
                {
                    sb.AppendFormat("{0},", item);
                }
                Val(sb.ToString().TrimEnd(','));
            }
        }

        public virtual void BindEvent(string eventname, Delegate del)
        {
            BindEventClass.BindEvent(_control, eventname, del);
        }

        #endregion
    }
}
